package GUI;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import ModelLayer.PartSale;
import ModelLayer.Sale;

//handle partsales
public class NewSaleModel extends AbstractTableModel {
	private static final long serialVersionUID = 1L;
		
	private ArrayList<?> container;
	private String[] columnNames;
		
		public NewSaleModel(String[] newSaleColumnNames, ArrayList<PartSale> list) {
			this.container = list;         
			this.columnNames = newSaleColumnNames;			
		}

		@Override
		public int getColumnCount() {
			return columnNames.length;
		}

		@Override
		public int getRowCount() {
			return container.size();
		}

		@Override
		public Object getValueAt(int rowIndex, int columnIndex) {
			PartSale ps =  (PartSale) container.get(rowIndex);
			
			//"Varekode", "Navn", "Antal", "Pris", "Total prisen"
			if(columnIndex == 0) {
				return ps.getItem().getItemCode();
			} 
			
			if(columnIndex == 1) {
				return ps.getItem().getName();
			}
			
			if(columnIndex == 2) {
				return ps.getAmount();
			}
			
			if(columnIndex == 3) {
				return ps.getItem().getPrice();
			}
			
			if(columnIndex == 4) {
				return (ps.getAmount() * ps.getItem().getPrice());
			}
			
			return null;
		}
		
		@Override
     public boolean isCellEditable(int rowIndex, int columnIndex) {
             return false;
     }   
		
		@Override
		public String getColumnName(int index) {
		    return columnNames[index];
		}
		
}

	

